package com.example.bitcoin;

import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;

public class MainActivity extends Activity {

	private EditText text;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
		setContentView(R.layout.activity_main);
		text = (EditText) findViewById(R.id.amount);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void onClick(View view)
	{
		switch(view.getId())
		{
			case R.id.calculateButton:
				
				String currency = "PLN";
				RadioButton eurRadio = (RadioButton) findViewById(R.id.eurRadio);
				RadioButton plnRadio = (RadioButton) findViewById(R.id.plnRadio);
				RadioButton gbpRadio = (RadioButton) findViewById(R.id.gbpRadio);
				RadioButton usdRadio = (RadioButton) findViewById(R.id.usdRadio);
				if(eurRadio.isChecked()) currency = "EUR";
				if(plnRadio.isChecked()) currency = "PLN";
				if(gbpRadio.isChecked()) currency = "GBP";
				if(usdRadio.isChecked()) currency = "USD";

				double amount = Double.parseDouble(text.getText().toString());
				
				TextView result = (TextView) findViewById(R.id.result);
				double converted = Downloader.readValue(currency, amount);
				result.setText(String.valueOf(converted));
				
				break;
				
		}
	}
	
	/*		 */

}
